// require http module
var http = require('http');
var url = require('url');
var exec = require('child_process').exec;
/**
 * createServer's callback
 * 
 * @param {any} request 
 * @param {any} response 
 */
function start(router, handle){
    function onRequest(request, response){
        var pathname = url.parse(request.url).pathname;
        var postData = '';
        request.setEncoding('utf8');
        request.addListener('data', function(chunk){
            postData += chunk;
            console.log(postData);
        });

        request.addListener('end', function(){
            router(handle, pathname, response, postData);
        })
    }
    // createServer
    http.createServer(onRequest).listen(8888);
}

exports.start = start;